package com.xiaoyu.lanling.feature.guard.activity

import android.os.Bundle
import com.xiaoyu.base.app.AppContext
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.activity.base.AppCompatToolbarActivity
import com.xiaoyu.lanling.feature.guard.data.GuardListData
import com.xiaoyu.lanling.feature.guard.fragment.GuardListFragment
import com.xiaoyu.lanling.view.FragmentAdapter
import com.xiaoyu.lanling.view.OnShowFragment
import com.xiaoyu.lanling.widget.tablayout.ScaleTabLayoutUtils
import kotlinx.android.synthetic.main.guard_list_activity.*
import kotlinx.android.synthetic.main.guard_list_toolbar.*

class GuardListActivity : AppCompatToolbarActivity() {

    override fun onCreateSafelyAfterAppFinishInit(savedInstanceState: Bundle?) {
        super.onCreateSafelyAfterAppFinishInit(savedInstanceState)
        setLightStatusBar()
        setContentView(R.layout.guard_list_activity)
        initToolbar()

        initViewPager()
    }

    private fun initViewPager() {
        val titles = listOf(AppContext.getString(R.string.guard_list_title_my_guard), AppContext.getString(R.string.guard_list_title_guard))

        val fragmentList = mutableListOf<OnShowFragment>().apply {
            add(GuardListFragment.newInstance(GuardListData.TYPE_MY_GUARD))
            add(GuardListFragment.newInstance(GuardListData.TYPE_GUARD))
        }

        val adapter = FragmentAdapter(supportFragmentManager, fragmentList, titles)
        view_pager.offscreenPageLimit = fragmentList.size
        view_pager.adapter = adapter
        ScaleTabLayoutUtils.createNormalScaleTabLayout(indicator, view_pager, titles, false)
    }
}